#include <bits/stdc++.h>
// 2025/07/10
// tag: 
// Author: Forever
using namespace std;
using int64 = int64_t;

int f[105][105];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    int w;
    cin >> w;
    while (w--) {
        int n, m;
        cin >> n >> m;
        memset(f, 0x3f, sizeof(f));

        for (int i = 1; i <= n + 1; i++)
            f[i][i] = 0;

        for (int i = 0; i < m; i++) {
            int s, t, v;
            cin >> s >> t >> v;
            f[s][t + 1] = min(f[s][t + 1], v);
            f[t + 1][s] = min(f[t + 1][s], -v);
        }
        for (int k = 1; k <= n + 1; k++)
            for (int i = 1; i <= n + 1; i++)
                for (int j = 1; j <= n + 1; j++)
                    if (f[i][k] != 0x3f3f3f3f && f[k][j] != 0x3f3f3f3f)
                        f[i][j] = min(f[i][j], f[i][k] + f[k][j]);

        bool flag = true;
        for (int i = 1; i <= n + 1; i++) {
            if (f[i][i] < 0) {
                flag = false;
                break;
            }
        }

        cout << (flag ? "true" : "false") << endl;
    }
    return 0;
}